{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form gg-form-bar border-t border-x">

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderNum" placeholder="单号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="pName" placeholder="客户" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="saleUnit" placeholder="销售单位" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="saleUser" placeholder="销售员" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="brand" placeholder="品牌" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="mdName" placeholder="品名" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="specs" placeholder="型号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="buyCode" placeholder="订货号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderDate" placeholder="单据日期" readonly id="orderDate" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <select name="payType" lay-search>
            <option value="">付款方式</option>
            {volist name='payTypeList' id='ptl'}
            <option value="{$ptl.id}">{$ptl.name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-input-inline" style="width:150px;">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
        <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
    </div>
</form>
<div class="p-3">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
<!--        <button class="layui-btn layui-btn-sm addNew" lay-event="add" type="button">+ 添加报价</button>-->

<!--        <button class="layui-btn layui-btn-sm layui-btn-primary" id="import" >导入</button>-->
<!--        <a href="{:url('api/ExportModel/QuotationOrderImportModel')}" target="_blank" class="layui-btn layui-btn-sm layui-btn-primary">导入模板</a>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-danger " lay-event="del" type="button">删除</button>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-danger " lay-event="ht" type="button">转合同</button>-->
        <!--      <a class="layui-btn layui-btn-sm layui-btn-normal " target="_blank" href="{:url('exportData')}">导出</a>-->
    </div>
</script>
<script type="text/html" id="actionBar">


<!--    <button class="layui-btn layui-btn-normal  layui-btn-xs" lay-event="edit">编辑</button>-->
<!--    <button class="layui-btn layui-btn-normal  layui-btn-xs" lay-event="detail">详情</button>-->
<!--    &lt;!&ndash;    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>&ndash;&gt;-->
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form;
        var upload=layui.upload;
        layui.laydate.render({
            elem:'#orderDate',
            range:'~'
        })
        var tableIns = table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            // ,defaultToolbar:  ['filter',  'exports']
            ,title:'报价'
            ,url: "{:url('index')}"
            ,page: true
            ,cellMinWidth: 80
            ,cols: [[
                {type: 'checkbox', fixed: 'left' },
                {fixed: 'left',field: 'id',title: 'ID' ,unresize: true,hide:true},
                {field:'orderNum', title: '单号', align:'center'}
                ,{field:'pName',title: '客户'}
                ,{field:'orderDate',title: '单据日期'}
                ,{field:'payTypeName',title: '付款方式'}
                ,{field:'dayLongs',title: '有效天数'}
                ,{field:'saleUnit',title: '销售单位'}
                ,{field:'saleName',title: '销售员'}
                ,{field:'tax',title: '税率'}
                ,{field:'mdBrand',title: '品牌'}
                ,{field:'mdName',title: '品名'}
                ,{field:'specs',title: '型号'}
                ,{field:'buyCode',title: '订货号'}
                ,{field:'mdUnit',title: '单位'}
                ,{field:'bjNum',title: '数量'}
                ,{field:'bjPrice',title: '含税单价'}
                ,{field:'noTaxPrice',title: '未税单价'}
                ,{field:'bjMoney',title: '含税小计'}
                ,{field:'bjTime',title: '货期'}
                ,{field:'remark',title: '备注'}
                // ,{field:'orderDate',title: '单据日期'}
                // ,{field:'status', title: '状态',width:80,align:'center',templet: function(d){
                //         var html1='<span class="">正常</span>';
                //         var html2='<span class="">已确认</span>';
                //         if(d.status==1){
                //             return html1;
                //         }
                //         else{
                //             return html2;
                //         }
                //     }}
                // ,{title: '操作',fixed: 'right',width: 200, align:'center', toolbar: '#actionBar'}
            ]]
        });
        //监听搜索提交
        form.on('submit(webform)', function (data) {
            console.log('data',data)
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        table.on('tool(test)',function (obj) {
            if(obj.event === 'edit'){
                tool.side("{:url('add')}?id=" + obj.data.id);
            }
            if(obj.event === 'detail'){
                tool.side("{:url('info')}?id=" + obj.data.id);
            }

            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("{:url('delete')}", {id: obj.data.id}, callback);
                    layer.close(index);
                });
            }
        });
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch(obj.event){
                case 'add':
                    tool.side("{:url('add')}");
                    break;
                case 'del':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            tool.delete("{:url('delete')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'ht':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })

                        httpRequest("{:url('toHetong')}",{ids:ids.join(',')},function (res) {
                            if (res.code == 0) {
                                tableIns.reload();
                            }
                        })
                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'import':

                    break;
                case 'forbid':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length) {
                        data.forEach(function (value, index) {
                            console.log('value', value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要禁用该类别吗?', {icon: 3, title:'提示'}, function(index){
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            httpRequest("{:url('doCheck')}", { id: ids.join(','),status: 2}, callback);
                            layer.close(index);
                        });
                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'resume':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length) {
                        data.forEach(function (value, index) {
                            console.log('value', value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要启用该类别吗?', {icon: 3, title:'提示'}, function(index){
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            httpRequest("{:url('doCheck')}", { id: ids.join(','),status: 1}, callback);
                            layer.close(index);
                        });
                    }else {
                        layer.msg('请选择数据');
                    }

                    break;

            };
        })

        var loadingIndex='';
        upload.render({
            elem: '#import'
            ,url: "{:url('importData')}"
            ,accept: 'file'
            ,exts: 'xlsx',
            before:function (res) {
                loadingIndex=layer.load(1,{
                    shade: [0.5,'#a09b9b']
                });
            }
            ,done: function(res){
                layer.msg(res.msg)
                layer.close(loadingIndex)
                setTimeout(function () {
                    location.reload()
                },2000)
            },
            error(e){
                layer.msg('网络异常请稍后再试')
                layer.close(loadingIndex)
            }
        });

    }
</script>
{/block}
<!-- /脚本 -->